/**
 * Created by gongxun on 17/5/19.
 */

var KwxNotFriendLayer = KwxBaseLayer.extend({
    PageView_list : null,
    //分页
    Image_fenyes : null,
    //推荐群
    mTuijianqunStr : null,
    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/KwxNotFriendLayer.json");
        mo.gameHelper.fixIosText(this.ccsNode);
        this.PageView_list = mo.seekWidgetByName(this.ccsNode, "PageView_list");

        //关闭
        mo.seekWidgetByName(this.ccsNode, "Button_ok").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.removeFromParent();
            }
        }, this);

        //关闭
        mo.seekWidgetByName(this.ccsNode, "Button_close").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.removeFromParent();
            }
        }, this);

        //复制推荐群
        mo.seekWidgetByName(this.ccsNode, "Image_tuijian").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                if (this.mTuijianqunStr != null){
                    mo.nativeHelper.copyString(this.mTuijianqunStr.toString());
                    mo.showRoomMsgShow("复制成功");
                }
            }
        }, this);

        //分页
        this.Image_fenyes = [];
        var Panel_fenye = mo.seekWidgetByName(this.ccsNode, "Panel_fenye");
        for (var i = 0; i < 4; i++){
            var Image_fenye = mo.seekWidgetByName(Panel_fenye, "Image_fenye" + i);
            this.Image_fenyes.push(Image_fenye);
            Image_fenye.setVisible(false);
        }

        var that = this;
        this.PageView_list.addEventListener(function(sender, type){
            that.updateIndex();
        });
    },

    onEnter : function(){
        this._super();
        mo.soundHelper.playDialogOpen();
        this.PageView_list.scrollToPage(0);
        this.updateIndex();

        //找到对应的code
        if (cc.sys.isNative) {
            var that = this;
            mo.httpClient.sendLocationNameToHtml(function (isSuccess, url) {
                if (isSuccess) {
                    cc.log("对应的url是:" + url);
                    that.setTuijianqun(url);
                } else {
                    cc.log("没有找到url");
                }
            });
        }
    },


    //更新分页小圆点
    updateIndex : function(){
        var count = this.PageView_list.getItems().length;
        var index = this.PageView_list.getCurrentPageIndex();
        var xAdd = 30;
        var startX = -(count - 1) * xAdd / 2;
        for (var i = 0; i < this.Image_fenyes.length; i++){
            if (i < count){
                this.Image_fenyes[i].setVisible(true);
                this.Image_fenyes[i].loadTexture(index == i ? "res/ccs/hall_second/userAgreement/img_select1.png" : "res/ccs/hall_second/userAgreement/img_select0.png");
                this.Image_fenyes[i].setPositionX(startX + xAdd * i);

            }else{
                this.Image_fenyes[i].setVisible(false);
            }
        }
    },

    //设置推荐微信群
    setTuijianqun : function(tuijianqunStr){
        this.mTuijianqunStr = tuijianqunStr;

        var Text_tuijian = mo.seekWidgetByName(this.ccsNode, "Text_tuijian");
        mo.gameHelper.setTextString(Text_tuijian, "       推荐微信群:" + tuijianqunStr + "(点击复制)\n进群后可以直接和群员一起游戏!")
    }
});